package com.sajhasite.dao;

import java.io.Serializable;

import javax.inject.Inject;


import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;

import com.sajhasite.domain.entity.BaseEntity;

public abstract class AbstractDaoHibernate<T extends BaseEntity, I extends Serializable> implements IBaseDao<T, I> {
	
	@Inject
	private SessionFactory sessionFactory;

	
	protected Session getSession() {
		return sessionFactory.getCurrentSession();
	}

	@Override
	public void delete(T t) {
		this.getSession().delete(t);
	}

	@SuppressWarnings("unchecked")
    @Override
	public T get(Class<T> clazz, I id) {
		return (T) this.getSession().get(clazz, id);
	}

	@Override
	public Query getNamedQuery(String queryName) {
		return this.getSession().getNamedQuery(queryName);
	}

	@SuppressWarnings("unchecked")
    @Override
	public T load(Class<T> clazz, I id) {
		return (T) this.getSession().load(clazz, id);
	}

	@SuppressWarnings("unchecked")
    @Override
	public T merge(T t) {
		return (T) this.getSession().merge(t);
	}

	@Override
	public void persist(T t) {
		this.getSession().persist(t);
	}

	@SuppressWarnings("unchecked")
    @Override
	public I save(T t) {
		return (I) this.getSession().save(t);
	}

	@Override
	public void update(T t) {
		this.getSession().update(t);
	}

	@Override
	public void saveOrUpdate(T t) {
		this.getSession().saveOrUpdate(t);
	}
}
